//创建一个水平无限长的顶部导航栏
export default class horizontalScroll {
  private el: HTMLElement;

  constructor(nativeElement: HTMLElement) {
    this.el = nativeElement;
    this.handleWheelEvent();
  }

  handleWheelEvent() {
    let wheel = "";

    if ("onmousewheel" in this.el) {
      wheel = "mousewheel";
    } else if ("onwheel" in this.el) {
      wheel = "wheel";
    } else if ("attachEvent" in window) {
      wheel = "onmousewheel";
    } else {
      wheel = "DOMMouseScroll";
    }
    this.el["addEventListener"](wheel, this.scroll);
  }

  scroll = (event: any) => {
    if (this.el.clientWidth >= this.el.scrollWidth) {
      return;
    }
    event.preventDefault();
    this.el.scrollLeft += event.deltaY
      ? event.deltaY
      : event.detail && event.detail !== 0
      ? event.detail
      : -event.wheelDelta;
  };
}
